<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>  
<c:set var="ctx" value="${pageContext.request.contextPath }" />
<link rel="stylesheet"
	href="${ctx }/resources/js/select2/select2.min.css" />
<script type="text/javascript"
	src="${ctx }/resources/js/select2/select2.min.js"></script>
<script type="text/javascript"
	src="${ctx }/resources/js/select2/zh-CN.js"></script>
	<script type="text/javascript">
$(function() {
	webside.form.subject.initResource();
	 webside.form.subject.subjectForm(); 
})
</script>
<script src="${ctx }/resources/js/upload/ajaxfileupload.js"
	type="text/javascript"></script>
<script type="text/javascript">
<!--

//-->
function doSaveAd() {
	 var fileName = $("#subjectPic").val();
	    var type = fileName.split(".");
	    var ftype = type[type.length - 1]; //获取文件后缀
	    $.ajaxFileUpload({
	        url: '${ctx }/files/upload/' + ftype,
	        secureuri: false, //是否需要安全协议，一般设置为false
	        fileElementId: ['subjectPic'], //文件上传域的ID
	        dataType: 'json', //返回值类型 一般设置为json
	        success: function (data, status) //服务器成功响应处理函数
	        {
	        	 
	            if (data.result == 0) {
	            	var fileId = data.data[0].id;
	            	var filePath = '/files/view/jpg/' + fileId;
	            	$("#hiddenResourceUrl").val(filePath);
	            	//显示图片
					$("#imgCover").attr("src",'${ctx}/files/view/jpg/' + fileId);
					//显示名字
					$("#labcover").html(data.data[0].name);
	            }
	        },
	        error: function (data, status, e) //服务器响应失败处理函数
	        {
	            alert(e);
	        }
	});
	
}

</script>

<style>
.iconShow
{
	padding-left: 10px; 
	padding-top: 3px;
}
.source-icon
{
	 width:95%;
	 float:left;
}
@media screen and (max-width: 374px){
	.source-icon
	{
		 width:82%;
	}
}
@media screen and (min-width: 375px) and (max-width: 449px){
	.source-icon
	{
		 width:85%;
	}
}
@media screen and (min-width: 450px) and (max-width: 1279px) {
	.source-icon
	{
		 width:90%;
	}
}
@media screen and (min_width: 1280px) {
	.source-icon
	{
		 width:90%;
	}
}
</style>
<div class="page-header">
	<h1>
		<c:if test="${empty subject}">
		新增专题
		</c:if>
		<c:if test="${!empty subject}">
		编辑专题
		</c:if>
	</h1>
</div>
<div class="row" style="margin-top: 5px;">
	<div class="col-xs-12">
		<form id="subjectForm" name="subjectForm" class="form-horizontal"  role="form" method="post">
			  <c:if test="${!empty subject}">
				<%-- <input type="hidden" id="pageNum" name="pageNum" value="${page.pageNum }"> 
				<input type="hidden" id="pageSize" name="pageSize" value="${page.pageSize }"> 
				<input type="hidden" id="orderByColumn" name="orderByColumn" value="${page.orderByColumn }"> 
				<input type="hidden" id="orderByType" name="orderByType" value="${page.orderByType }"> --%>
				<input type="hidden"  id='id' name="id" value="${subject.id }">
			</c:if>  
			<input type="hidden"  id='adsubjectId' name="adsubjectId" value="${subjectId }">
			<div class="form-group">
				<label class="control-label col-sm-2 no-padding-right" for="name">专题名称</label>
				<div class="col-sm-8">
				<div class="clearfix">
					<input class="form-control" name="subjectName" id="subjectName" type="text"
						value="${subject.subjectName }" placeholder="专题名称" />
                </div>
				</div>
            </div>
            <div class="form-group">
				<label class="control-label col-sm-2 no-padding-right" for="name">专题简介</label>
				<div class="col-sm-8">
				<div class="clearfix">
					<input class="form-control" name="subjectSummary" id="subjectSummary" type="text"
						value="${subject.subjectSummary }" placeholder="专题简介" />
                </div>
				</div>
            </div>
             <div class="form-group">
				<label class="control-label col-sm-2 no-padding-right" for="name">专题图片</label>
				<div class="col-sm-8">
					<div class="clearfix">
						<input class="form-control" name="files" id="subjectPic" type="file"
		                  value="${subjectEntity.subjectPic }" />
		                 <img id="imgCover" alt="" 
		                 <c:if test="${'' eq  subjectEntity.subjectPic || null eq subjectEntity.subjectPic}">src="${ctx}/resources/images/xx.png"</c:if> 
		                 <c:if test="${subjectEntity.subjectPic != null}">src="${ctx}${subjectEntity.subjectPic}"</c:if>
		                  width="175px" height="100px">
						<label id="labcover" ></label>                
					<input class="btn btn-primary btn-sm" type="button" value="上传" onclick="doSaveAd();"/>
					 <input id="hiddenResourceUrl" name="subjectPic" type="hidden" />
					</div>
					<label id='c' style='font-family:verdana;color:red'>推荐尺寸230*329</label>
				</div>
            </div>
             <div class="form-group">
				<label class="control-label col-sm-2 no-padding-right" for="name">收录视频</label>
				<div class="col-sm-8">
				<div class="clearfix">
					<input class="form-control" id="resourceName" name="AddSeries" type="text"
							value="点击选择" placeholder="" />
					<i id="SeriesResourceShow" data-rel="tooltip" data-placement="left"  data-original-title="点击清除" </i>
						<input id="seriesId" name="seriesId" value="" type="text" style="display:none;"/>
                </div>
				</div>
            </div>
             <div class="form-group">
				<label class="control-label col-sm-2 no-padding-right" for="name">专题模板</label>
				<div class="col-sm-8">
				<div class="clearfix">
					<select id="subjectTemplateCode" class="form-control" name='subjectTemplateCode'>
						    <option typecode="" value="" <c:if test="${subject.subjectTemplateCode eq null}">selected="selected"</c:if>>请选择</option>
							<c:forEach items="${templateList}" var="t">
							<option typecode="${t.code }" value="${t.name}"<c:if test="${subject.subjectTemplateCode eq t.code}">selected="selected"</c:if>>${t.name}</option>
							</c:forEach>
						</select>
                </div>
				</div>
            </div>		
              
			
		</form>
		<div class="hr hr-dotted"></div>
	</div>
</div>
<div class="center">
	<button id="btnAdd" type="button" 
	onclick="javascript:$('#subjectForm').submit();" 
	class="btn btn-success btn-sm">
		<i class="fa fa-user-plus"></i>&nbsp;
		<c:if test="${empty subject}">
		添加
		</c:if>
		<c:if test="${!empty subject}">
		保存
		</c:if>
	</button>
	<button id="btn" type="button"
		onclick="webside.common.loadPage('/subject/listUI.html<c:if test="${!empty subject}">?page=${page.pageNum }&rows=${page.pageSize }&sidx=${page.orderByColumn }&sord=${page.orderByType }</c:if>')"
		class="btn btn-info btn-sm">
		<i class="fa fa-undo"></i>&nbsp;返回
	</button>
</div>
<script type="text/javascript">
$(document).ready(function(){ 
	var subid = "${subject.id}";
    if(subid!=null & subid!=0){
    	$("#adsubjectId").attr("value",subid);
    }
  }); 
</script>
 